﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace zUfDsl
{
    public static class DbCommandExt
    {
        #region 执行SQL语句
        /// <summary>
        /// 执行SQL语句
        /// </summary>
        public static int ExecSQL(this DbCommand cmd, string sql)
        {
            cmd.CommandText = sql;
            int iRowEffect;
            iRowEffect = cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            return iRowEffect;
        }
        #endregion
        #region 获取值
        /// <summary>
        /// 获取值
        /// </summary>
        public static object GetObj(this DbCommand cmd, string sql)
        {
            cmd.CommandText = sql;
            return cmd.ExecuteScalar();
        }
        #endregion
        #region 获取值
        /// <summary>
        /// 获取值
        /// </summary>
        public static DataTable GetDataTable(this DbCommand cmd, string sql)
        {
            cmd.CommandText = sql;
            var rs = cmd.ExecuteReader();
            var dt = new DataTable();
            dt.Load(rs);
            return dt;
        }
        #endregion       
    }
}
